package DataBaseModel;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DataBase {
	public static Connection getConn() throws SQLException {
		// 连接类，得到和目标数据库连接的对象
		Connection con = null;
		// 加载驱动

		try {
			Class.forName("com.mysql.jdbc.Driver");
			// 加载驱动类

			con = DriverManager
					.getConnection(
							"jdbc:mysql://localhost/SmartQQ??useUnicode=true&characterEncoding=utf-8&useSSL=false",
							"root", "123456");
			// 获取与目标数据库的连接，参数（"jdbc:mysql://localhost/数据库名"，"root"，"数据库密码"；

		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return con;
	}
	public static void main(String[] args) {
		try {
			Connection con=DataBase.getConn();
			System.out.println(con==null);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
